from PyQt4.QtGui import QDialog
from ui_options import Ui_Options

from common.terrain import Terrain
from mapeditor.core.memanager import MEManager

class OptionsDialog(QDialog, Ui_Options):
	"""
	CGCraft MapEditor's map options dialog.
	"""
	
	def __init__(self, parent=None):
		super(OptionsDialog, self).__init__(parent)
		self.setupUi(self)
		self.btnOk.setDefault(True)
		
		self.mapWidth.setValue(MEManager.map.terrain.width)
		self.mapHeight.setValue(MEManager.map.terrain.height)
		self.textDescription.appendPlainText(MEManager.map.description)
		self.winCTF.setChecked(MEManager.map.ctf_win)
		self.winDestroy.setChecked(MEManager.map.destroy_all_win)
		self.winHorn.setChecked(MEManager.map.horn_win)
		
		self.winCTF.setEnabled(False)
		self.winHorn.setEnabled(False)
		
	def __get_description(self):
		return str(self.textDescription.toPlainText())
	description = property(__get_description)
	
	def __get_width(self):
		return self.mapWidth.value()
	map_width = property(__get_width)
	
	def __get_height(self):
		return self.mapHeight.value()
	map_height = property(__get_height)
	
	def __get_winCTF(self):
		return self.winCTF.isChecked()
	ctf_win = property(__get_winCTF)
	
	def __get_winDestroyAll(self):
		return self.winDestroy.isChecked()
	destroy_all_win = property(__get_winDestroyAll)
	
	def __get_winHorn(self):
		return self.winHorn.isChecked()
	horn_win = property(__get_winHorn)